package com.shengong;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @ClassName ComparatorDemo
 * @Author shengong
 * @Date 2019-06-01 14:39
 * @Description Comparator定制排序
 */
public class ComparatorDemo {

    /**
     * 功能描述: <br>
     * @Param: [args]
     * @Return: void
     * @Author: shengong
     * @Date: 2019/6/1/0001 15:34
     */
    public static void main(String[] args) {
        List<Integer> arrayList = new ArrayList<Integer>();
        arrayList.add(-1);
        arrayList.add(3);
        arrayList.add(3);
        arrayList.add(-5);
        arrayList.add(7);
        arrayList.add(4);
        arrayList.add(-9);
        arrayList.add(-7);
        System.out.println("原始数组:");
        System.out.println(arrayList);
        Collections.reverse(arrayList);
        System.out.println("反转数组:");
        System.out.println(arrayList);

        Collections.sort(arrayList);
        System.out.println("自然排序升序：");
        System.out.println("arrayList = " + arrayList);

        Collections.sort(arrayList, new Comparator<Integer>() {
            public int compare(Integer o1, Integer o2) {
                return o2.compareTo(o1);
            }
        });
        System.out.println("定制排序：");
        System.out.println("arrayList = " + arrayList);

    }

}
